{% extends 'base_order.html' %}
{% block title %}天天生鲜-提交订单{% endblock title %}


{% block order_title %}提交订单{% endblock order_title %}

{% block body %}
	<h3 class="common_title">确认收货地址</h3>

	<div class="common_list_con clearfix">
		<dl>
			<dt>寄送到：</dt>
            {% for address in address_list %}
                {% if address.is_default %}
			<dd><input type="radio" name="address" checked value={{ address.id }}>{{ address.addr}} （{{ address.receiver }} 收） {{ address.phone}}</dd>
                {% else %}
            <dd><input type="radio" name="address" value={{ address.id }}>{{ address.addr}} （{{ address.receiver }} 收） {{ address.phone}}</dd>
                {% endif %}
            {% empty %}
            {% endfor %}
		</dl>
		<a href="{% url 'user:address' %}" class="edit_site">编辑收货地址</a>

	</div>
	
	<h3 class="common_title">支付方式</h3>	
	<div class="common_list_con clearfix">
		<div class="pay_style_con clearfix">
			<input type="radio" name="pay_style" value="1">
			<label class="cash">货到付款</label>
			<input type="radio" name="pay_style" value="2">
			<label class="weixin">微信支付</label>
			<input type="radio" name="pay_style" value="3" checked>
			<label class="zhifubao"></label>
			<input type="radio" name="pay_style" value="4">
			<label class="bank">银行卡支付</label>
		</div>
	</div>

	<h3 class="common_title">商品列表</h3>
	
	<div class="common_list_con clearfix">
		<ul class="goods_list_th clearfix">
			<li class="col01">商品名称</li>
			<li class="col02">商品单位</li>
			<li class="col03">商品价格</li>
			<li class="col04">数量</li>
			<li class="col05">小计</li>		
		</ul>
		<ul class="goods_list_td clearfix">
			<li class="col01">1</li>
			<li class="col02"><img src="{{ goods.image.url }}"></li>
			<li class="col03">{{ goods.name }}</li>
			<li class="col04">{{ goods.unite }}</li>
			<li class="col05">{{ goods.price }}元</li>
			<li class="col06">{{ goods_count }}</li>
			<li class="col07">{{ goods_totail }}元</li>
		</ul>
{#		<ul class="goods_list_td clearfix">#}
{#			<li class="col01">2</li>			#}
{#			<li class="col02"><img src="../static/images/goods/goods003.jpg"></li>#}
{#			<li class="col03">大兴大棚草莓</li>#}
{#			<li class="col04">500g</li>#}
{#			<li class="col05">16.80元</li>#}
{#			<li class="col06">1</li>#}
{#			<li class="col07">16.80元</li>	#}
{#		</ul>#}
	</div>

	<h3 class="common_title">总金额结算</h3>

	<div class="common_list_con clearfix">
		<div class="settle_con">
			<div class="total_goods_count">共<em>{{ goods_count }}</em>件商品，总金额<b>{{ goods_totail }}元</b></div>
{#			<div class="transit">运费：<b>10元</b></div>#}
			<div class="total_pay">实付款：<b>{{ goods_totail }}元</b></div>
		</div>
	</div>

	<div class="order_submit clearfix">
		<a href="javascript:;" id="order_btn">提交订单</a>
	</div>	

{% endblock body %}
    {% block buttom_info %}
	<div class="footer">
		<div class="foot_link">
			<a href="#">关于我们</a>
			<span>|</span>
			<a href="#">联系我们</a>
			<span>|</span>
			<a href="#">招聘人才</a>
			<span>|</span>
			<a href="#">友情链接</a>		
		</div>
		<p>CopyRight © 2016 北京天天生鲜信息技术有限公司 All Rights Reserved</p>
		<p>电话：010-****888    京ICP备*******8号</p>
	</div>

	<div class="popup_con">
		<div class="popup">
			<p>订单提交成功！</p>
		</div>
		
		<div class="mask"></div>
    {% csrf_token %}
	</div>
    {% endblock buttom_info %}

    {% block buttom_js %}
	<script type="text/javascript" src="../static/js/jquery-3.6.0.min.js"></script>
	<script type="text/javascript">
		$('#order_btn').click(function() {
            var address_id = $("input[name='address']:checked").val();
            var paystyle_id = $("input[name='pay_style']:checked").val();
            var totail_count = {{ goods_count }}
            var totail_price = {{ goods_totail }}
            var goods_id = {{ goods.id }}
            var csrftoken = $("input[name='csrfmiddlewaretoken']").val();
            var context = {
            "address_id": address_id,
            "paystyle_id": paystyle_id,
            "totail_count": totail_count,
            "totail_price": totail_price,
            "goods_id": goods_id,
            "csrfmiddlewaretoken": csrftoken,
        }

        $.post('http://127.0.0.1:8000/order/pay', context, function (response) {
            if (response.errno == '1'){
                window.location.href = response.pay_url
            }
            else{
                window.location.href = response.url
            }
        })


		});
	</script>
   {% endblock buttom_js %}
